package br.com.sistema.view.lookups;

import com.vaadin.data.Container;
import com.vaadin.event.ShortcutAction.KeyCode;
import com.vaadin.shared.ui.MarginInfo;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

public abstract class AbstractLookupView extends Window {

	private static final long serialVersionUID = 1L;
	
	private GridLayout component = new GridLayout();
	private Table table= new Table();
	private Button seleciona = new Button("Selecionar");
	private Button pesquisa = new Button("Pesquisa");
	
	public void init(){
		
		table.setContainerDataSource(getBeanContainer());
		table.setVisibleColumns(getVisibleColumns());
		table.setColumnHeaders(getColumnHeaders());
		table.setSizeFull();
		table.setMultiSelect(false);
		table.setSelectable(true);
		table.setImmediate(true);
		
		VerticalLayout v0 = new VerticalLayout();
		v0.setMargin(new MarginInfo(false, false, true, false));
		v0.addComponent(getSearchArea());
		
		HorizontalLayout h0 = new HorizontalLayout();
		h0.setSpacing(true);
		h0.setMargin(new MarginInfo(true, false, false, false));
		h0.addComponent(seleciona);

		((GridLayout) component).setMargin(true);
		((GridLayout) component).setSizeFull();
		((GridLayout) component).setColumns(1);
		((GridLayout) component).setRows(3);
		((GridLayout) component).addComponent(v0, 0, 0);
		((GridLayout) component).addComponent(table, 0, 1);
		((GridLayout) component).addComponent(h0, 0, 2);
		((GridLayout) component).setRowExpandRatio(1, 1);
		
		setWidth("510");
		setHeight("300");
		setResizable(false);
		setModal(true);
		center();
		setContent(component);
		
		this.setCloseShortcut(KeyCode.ESCAPE, null);

	}
	
	public abstract Object[] getVisibleColumns();
	public abstract String[] getColumnHeaders();
	public abstract Container getBeanContainer();
	public abstract Component getSearchArea();
	
	public Component getComponent(){
		return component;
	}
	
	public Button getSeleciona() {
		return seleciona;
	}

	public Button getPesquisa() {
		return pesquisa;
	}
	
	public Table getTable(){
		return table;
	}
}
